﻿

<TestClass()> Public Class UnitTest1

    <TestMethod()> Public Sub CacheInstanceTest()
        Dim iocc = Ioc.Container.GetInstance(Of ITestInter)()
        Assert.IsNotNull(iocc)
    End Sub

    <TestMethod()>
    Public Sub CacheTest()
        Dim itester = Ioc.Container.GetInstance(Of ITestInter)()
        Assert.IsNotNull(itester)
        itester.EmptyMethod()
        Assert.AreEqual(itester.ReadOnlyProp, "EmptyMethod")
        itester.EmptyMethodWithParam("TestParam")
        Assert.AreEqual(itester.ReadOnlyProp, "TestParam")
        itester.Prop = "MyProp"
        Assert.AreEqual(itester.ReadOnlyProp, "MyProp")
        itester.WriteOnlyProp = "MyWriteProp"
        Assert.AreEqual(itester.ReadOnlyProp, "MyWriteProp")
        itester.PropWithParam("tester") = "MyProp"
        Assert.AreEqual(itester.ReadOnlyProp, "testerMyProp")
        Assert.AreEqual(itester.ReadOnlyPropWithParam("testReadonlyparam"), "testReadonlyparam")
    End Sub

    <TestMethod()>
    Public Sub CacheHitTest()
        Dim itester = Ioc.Container.GetInstance(Of ITestInter)()
        Ioc.Container.SetSingletonCached(GetType(ITestInter), GetType(TestInter), True)
        TestInter.Hits = 0
        Assert.IsNotNull(itester)
        itester.Prop = "MyProp"
        For x As Integer = 0 To 1000000
            Assert.AreEqual(itester.Prop, "MyProp")
        Next
        Assert.AreEqual(TestInter.Hits, 2)
    End Sub
End Class